<?php
namespace Home\Common;
use Org\Util\Mysql;

class Makelog extends Mysql{
	//编译记录写入
	function writeMakeLog($game_name,$game_version,$game_content,$game_channel,$thedate,$make_ip){
		$insert = $this->mysql->prepare("insert into game_make(game_name,game_version,game_channel,game_content,thedate,make_ip) 
				values ('$game_name','$game_version','$game_channel','$game_content','$thedate','$make_ip')");
		$result = $insert->execute();
		
		if($result) return true;
		else 		return false;
	}
	//编译记录读取
	function getMakeLog($game_name){
		$select = $this->mysql->prepare("select * from game_make where game_name = '$game_name' order by id desc limit 0,20");
		$select->execute();
		
		$arResult = array();
		while($row = $select->fetch(\PDO::FETCH_ASSOC)){
			array_push($arResult, array($row['game_name'],$row['game_version'],$row['game_channel'],$row['game_content'],$row['thedate'],$row['make_ip']));
		}
		return $arResult;
	}
	//下载记录写入
	function writeDownLog($game_name,$game_version,$game_channel,$thedate,$down_ip){
		$insert = $this->mysql->prepare("insert into game_down(game_name,game_version,game_channel,thedate,down_ip)
				values ('$game_name','$game_version','$game_channel','$thedate','$down_ip')");
		$result = $insert->execute();
	
		return $result?true:false;
	}
	//下载记录读取
	function getDownLog($game_name){
		$select = $this->mysql->prepare("select * from game_down where game_name = '$game_name' order by id desc limit 0,20");
		$select->execute();
	
		$arResult = array();
		while($row = $select->fetch(\PDO::FETCH_ASSOC)){
			array_push($arResult, array($row['game_name'],$row['game_version'],$row['game_channel'],$row['game_content'],$row['thedate'],$row['down_ip']));
		}
		return $arResult;
	}
	//获取最新编译条目（下载列表)
	function getDownList(){
		$select = $this->mysql->prepare("select a.* from game_make a where id = (select max(id) from 
				game_make where game_channel = a.game_channel) order by game_version desc");
		$select->execute();
		
		$arResult = array();
		while($row = $select->fetch(\PDO::FETCH_ASSOC)){
			array_push($arResult,array($row['id'],$row['game_name'],$row['game_version'],$row['game_channel'],$row['game_content'],$row['thedate']));
		}
		
		return $arResult;
	}
}
